﻿@{
    ViewBag.Title = "About";
}
<div style="height:100%">
    <div style="background-color: #fff; height: 100%; display: flex; flex-direction: column;border-right:1px solid #808080;" class="col-lg-4">
        <label>发货请检单</label>
        <input type="text" id="shusng" list="seleect_codeDE" />
        <datalist id="seleect_codeDE" class="form-control" style="display:none">
        </datalist>
        <label>编码</label>
        <input type="text" id="danhsuj" /><span class="tto"></span>
        <label>发货请检单行号</label>
        <input type="text" id="jainas" /><span class="tto"></span>
        <div>
            <button id="queding">查询</button>
            <button id="Noque">打印</button>
        </div>
    </div>
    <div style="background-color: #fff; height: 100% " class="col-lg-8">
        <table class="table tab" border="1">
            <thead>
                <tr style="text-align:center">
                    <td>行号</td>
                    <td>编码</td>
                    <td>客户</td>
                    <td>物料编码</td>
                    <td>物料名</td>
                    <td>物料规格</td>
                    <td>订单数量</td>
                    <td>计量单位</td>
                </tr>
            </thead>
            <tbody id="csjind" style="height:500px">
            </tbody>
        </table>
    </div>
</div>
@section scripts{
    <script>
        $(function () {
            Chax()
            function Chax() {
                var sjind = $("#shusng").val()
                var sjinded = $("#jainas").val()
                var LLOK = $("#danhsuj").val()
                console.log(sjind)
                $.ajax({
                    url: '/Home/About',
                    type: 'POST',
                    data: { "stace": 1, "combs": sjind, "shulian": sjinded, "shinf": LLOK },
                    success: function (date) {
                        createRow(date);
                    },
                    error: function (date) {
                        alert(date);
                    }
                })
            }
           
            function createRow(e) {
                console.log(e)
                $("#csjind tr").remove();
                $("#seleect_codeDE option").remove();
                var index = 1
                $.each(e, function (i, item) {
                    var $tr = $(`
                    <tr class="djgewj">
                        <td>${index}</td>
                        <td>${item.encoding}</td>
                        <td>${item.Shipping}</td>
                        <td>${item.FMaterial}</td>
                        <td class="wlm">${item.Material}</td>
                        <td>${item.specification}</td>
                        <td>${item.quantity}</td>
                        <td>${item.Unit}</td>
                    </tr>
                    `)
                    $("#csjind").append($tr);
                    index++
                    //$(".djgewj").each(function (i, obj) {
                    //    console.log(11)
                    //    var wl = $("td[class=wlm]",obj).text()
                    //    if (wl == item.Material) {
                    //        var suliang = $(obj).next().next().text() * 1
                    //        var shul2 = item.quantity * 1
                    //        console.log(suliang , shul2)
                    //        $(obj).next().next().text(suliang + shul2)
                    //    }
                    //    else {
                            
                    //    }
                    //})
                    
                    var $opt = $(`<option>${item.encoding}</option>`)
                    $("#seleect_codeDE").append($opt);
                })
            }
            $("#queding").click(function () {
                Chax()
            })
            $("#Noque").click(function () {
                var sjind = $("#shusng").val()
                var kodes = $("#jainas").val()
                var kksjjs = $("#danhsuj").val()
                if (kodes == "") {
                    $(".tto").text("行号不能为空")

                } else {
                    window.location.href = "/Dyin/Index?shulian=" + kodes + "&comdj=" + sjind + "&stace=" + 2 + "&JINS=" + kksjjs;
                }
            })
        })
    </script>
}